package com.xxx.modules.sys.service.impl;

import com.xxx.modules.sys.domain.SysUserTextCollectionDomain;
import com.xxx.modules.sys.service.SysUserTextCollectionService;
import com.xxx.modules.sys.service.UserTextCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by ChenXuefei on 2017/10/17.
 */
@Service("userTextCollectionService")
public class UserTextCollectionServiceImpl implements UserTextCollectionService {

    @Autowired
    private SysUserTextCollectionService sysUserTextCollectionService;

    @Override
    public void addUserTextCollection(String collectionId, String textId) {
        SysUserTextCollectionDomain sysUserTextCollectionDomain = new SysUserTextCollectionDomain();
        sysUserTextCollectionDomain.setTextId(Long.valueOf(textId));
        sysUserTextCollectionDomain.setCollectionId(Long.valueOf(collectionId));
        //0 收藏  1取消收藏
        sysUserTextCollectionDomain.setState(0);
        sysUserTextCollectionDomain.setCreateTime(new Date());
        sysUserTextCollectionDomain.setUpdateTime(sysUserTextCollectionDomain.getCreateTime());

        sysUserTextCollectionService.add(sysUserTextCollectionDomain);
    }

    @Override
    public void updateUserTextCollectionSatate(String collectionId, String textId) {
        SysUserTextCollectionDomain sysUserTextCollectionDomain = new SysUserTextCollectionDomain();
        sysUserTextCollectionDomain.setCollectionId(Long.valueOf(collectionId));
        sysUserTextCollectionDomain.setTextId(Long.valueOf(textId));

        List<SysUserTextCollectionDomain> sysUserTextCollectionDomains = sysUserTextCollectionService.queryByList(sysUserTextCollectionDomain);
        SysUserTextCollectionDomain userTextCollectionDomain = sysUserTextCollectionDomains.get(0);

        //0 收藏  1取消收藏
        userTextCollectionDomain.setState(1);
        userTextCollectionDomain.setUpdateTime(new Date());
        sysUserTextCollectionService.updateBySelective(userTextCollectionDomain);
    }
}
